{% extends "base.html" %}
{# Copyright The IETF Trust 2015-2019, All Rights Reserved #}
{% load origin %}
{% load django_bootstrap5 static ietf_filters %}
{% block pagehead %}
    <link rel="stylesheet" href="{% static "ietf/css/list.css" %}">
    {{ review_wish_form.media.css }}
{% endblock %}
{% block title %}Review overview for {{ request.user }}{% endblock %}
{% block content %}
    {% origin %}
    <h1>
        Review overview
        <br>
        <small class="text-body-secondary">{{ request.user }}</small>
    </h1>
    <h2 class="mt-4">Assigned reviews</h2>
    {% if open_review_assignments %}
        <table class="table table-sm table-striped tablesorter">
            <thead>
                <tr>
                    <th scope="col" data-sort="document">Document</th>
                    <th scope="col" data-sort="version">Version Requested</th>
                    <th scope="col" data-sort="num">Current Version</th>
                    <th scope="col" data-sort="team">Team</th>
                    <th scope="col" data-sort="type">Type</th>
                    <th scope="col" data-sort="date">Deadline</th>
                </tr>
            </thead>
            <tbody>
                {% for r in open_review_assignments %}
                    <tr>
                        <td>
                            <a {% if r.pk != None %}href="{% url "ietf.doc.views_review.review_request" name=r.review_request.doc.name request_id=r.review_request.pk %}"{% endif %}>
                                {{ r.review_request.doc.name }}
                            </a>
                        </td>
                        <td>
                            {% if r.review_request.requested_rev %}
                                {{ r.review_request.requested_rev }}
                            {% else %}
                                Current
                            {% endif %}
                        </td>
                        <td>{{ r.review_request.doc.rev }}</td>
                        <td>
                            <a href="{% url 'ietf.group.views.review_requests' acronym=r.review_request.team.acronym %}">
                                {{ r.review_request.team.acronym }}
                            </a>
                        </td>
                        <td>{{ r.review_request.type.name }}</td>
                        <td>
                            {{ r.review_request.deadline|date:"Y-m-d" }}
                            {% if r.due %}<span class="badge rounded-pill text-bg-warning">{{ r.due }} day{{ r.due|pluralize }}</span>{% endif %}
                        </td>
                    </tr>
                {% endfor %}
            </tbody>
        </table>
    {% else %}
        <p>
            You do not have any open review requests assigned.
        </p>
    {% endif %}
    <h2 class="mt-4">Latest closed review assignments</h2>
    {% if closed_review_assignments %}
        <table class="table table-sm table-striped tablesorter">
            <thead>
                <tr>
                    <th scope="col" data-sort="document">Document</th>
                    <th scope="col" data-sort="num">Version Reviewed</th>
                    <th scope="col" data-sort="team">Team</th>
                    <th scope="col" data-sort="type">Type</th>
                    <th scope="col" data-sort="date">Deadline</th>
                    <th scope="col" data-sort="state">State</th>
                    <th scope="col" data-sort="result">Result</th>
                </tr>
            </thead>
            <tbody>
                {% for r in closed_review_assignments %}
                    <tr>
                        <td>
                            <a {% if r.pk != None %}href="{% url "ietf.doc.views_review.review_request" name=r.review_request.doc.name request_id=r.review_request.pk %}"{% endif %}>
                                {{ r.review_request.doc.name }}
                            </a>
                        </td>
                        <td>
                            {{ r.reviewed_rev|default:"See review" }}
                            {% if r.review_request.requested_rev %}
                                {% if r.review_request.requested_rev != r.reviewed_rev %}({{ r.review_request.requested_rev }} requested){% endif %}
                            {% endif %}
                        </td>
                        <td>
                            <a href="{% url 'ietf.group.views.review_requests' acronym=r.review_request.team.acronym %}">
                                {{ r.review_request.team.acronym }}
                            </a>
                        </td>
                        <td>{{ r.review_request.type.name }}</td>
                        <td>
                            {{ r.review_request.deadline|date:"Y-m-d" }}
                            {% if r.due %}<span class="badge rounded-pill text-bg-warning">{{ r.due }} day{{ r.due|pluralize }}</span>{% endif %}
                        </td>
                        <td>
                            {{ r.state.name|badgeify }}
                        </td>
                        <td>
                            {% if r.result %}{{ r.result.name }}{% endif %}
                        </td>
                    </tr>
                {% endfor %}
            </tbody>
        </table>
    {% else %}
        <p>
            Did not find any closed review requests assigned to you.
        </p>
    {% endif %}
    <h2 class="mt-4">
        Review wishes
    </h2>
    {% if review_wishes %}
        <p>
            You have indicated that you would like to review:
        </p>
        <table class="table table-sm table-striped tablesorter">
            <thead>
                <tr>
                    <th scope="col">
                        Document
                    </th>
                    <th scope="col">
                        Team
                    </th>
                    <th scope="col">
                    </th>
                </tr>
            </thead>
            <tbody>
                {% for w in review_wishes %}
                    <tr>
                        <td>
                            <a href="{% url "ietf.doc.views_doc.document_main" w.doc.name %}">
                                {{ w.doc.name }}
                            </a>
                        </td>
                        <td>
                            {{ w.team.acronym }}
                        </td>
                        <td>
                            <form method="post">
                                {% csrf_token %}
                                <input name="wish_id" value="{{ w.pk }}" type="hidden">
                                <button class="btn btn-sm btn-danger float-end"
                                        type="submit"
                                        name="action"
                                        value="delete_wish">
                                    Delete
                                </button>
                            </form>
                        </td>
                    </tr>
                {% endfor %}
            </tbody>
        </table>
    {% else %}
        <p>
            You do not have any review wishes.
        </p>
    {% endif %}
    {% if teams %}
        <p>
            Add an Internet-Draft that you would like to review when it becomes available for review:
        </p>
        <form method="post" class="form-inline">
            {% csrf_token %}
            {% bootstrap_form review_wish_form %}
            <button class="btn btn-primary" type="submit" name="action" value="add_wish">
                Add I-D
            </button>
        </form>
    {% endif %}
    {% for t in teams %}
        <h2 class="mt-4">
            Settings for {{ t }}
        </h2>
        <table class="table table-sm table-striped tablesorter">
            <thead>
                <tr>
                    <th scope="col" data-sort="setting">
                        Setting
                    </th>
                    <th scope="col" data-sort="value">
                        Value
                    </th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <th scope="row">
                        Can review
                    </th>
                    <td>
                        {{ t.reviewer_settings.get_min_interval_display|default:"No max frequency set" }}
                    </td>
                </tr>
                <tr>
                    <th scope="row">
                        Skip next assignments
                    </th>
                    <td>
                        {{ t.reviewer_settings.skip_next|yesno }}
                    </td>
                </tr>
                <tr>
                    <th scope="row">
                        Filter regexp
                    </th>
                    <td>
                        {% if t.reviewer_settings.filter_re %}
                            <code>{{ t.reviewer_settings.filter_re }}</code>
                        {% else %}
                            (None)
                        {% endif %}
                    </td>
                </tr>
                <tr>
                    <th scope="row">
                        Remind days before deadline
                    </th>
                    <td>
                        {{ t.reviewer_settings.remind_days_before_deadline|default:"(Do not remind)" }}
                    </td>
                </tr>
                <tr>
                    <th scope="row">
                        Periodic reminder of open reviews every X days
                    </th>
                    <td>
                        {{ t.reviewer_settings.remind_days_open_reviews|default:"(Do not remind)" }}
                    </td>
                </tr>
                <tr>
                    <th scope="row">
                        Select me next for an assignment
                    </th>
                    <td>
                        {{ t.reviewer_settings.request_assignment_next|yesno }}
                    </td>
                </tr>
                <tr>
                    <th scope="row">
                        Unavailable periods
                    </th>
                    <td>
                        {% if t.unavailable_periods %}
                            {% include "review/unavailable_table.html" with unavailable_periods=t.unavailable_periods %}
                        {% else %}
                            (No periods)
                        {% endif %}
                    </td>
                </tr>
            </tbody>
        </table>
        <div>
            <a class="btn btn-primary"
               href="{% url "ietf.group.views.change_reviewer_settings" group_type=t.type_id acronym=t.acronym reviewer_email=t.role.email.address %}?next={{ request.get_full_path|urlencode }}">
                Change settings
            </a>
        </div>
    {% empty %}
        <h2 class="mt-4">
            Settings
        </h2>
        <p>
            It looks like you are not a reviewer in any active review team.
        </p>
    {% endfor %}
{% endblock %}
{% block js %}
    {{ review_wish_form.media.js }}
    <script src="{% static "ietf/js/list.js" %}">
    </script>
{% endblock %}